package com.sc.study.exam.service.impl;

import java.util.List;

import com.sc.study.exam.domain.ScQuestion;
import com.sc.study.exam.mapper.ScQuestionMapper;
import com.sc.study.exam.mapper.ScTestexamQuestionMapper;
import com.sc.study.exam.service.IScQuestionService;
import com.sc.study.student.mapper.ScStudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sc.study.exam.mapper.ScStudentTestexamResultMapper;
import com.sc.study.exam.domain.ScStudentTestexamResult;
import com.sc.study.exam.service.IScStudentTestexamResultService;

/**
 * 学员考试结果Service业务层处理
 * 
 * @author sc
 * @date 2022-02-27
 */
@Service
public class ScStudentTestexamResultServiceImpl implements IScStudentTestexamResultService 
{
    @Autowired
    private ScStudentTestexamResultMapper scStudentTestexamResultMapper;


    @Autowired
    private ScStudentMapper scStudentMapper;

    @Autowired
    private ScTestexamQuestionMapper scTestexamQuestionMapper;

    @Autowired
    private IScQuestionService scQuestionService;

    /**
     * 查询学员考试结果
     * 
     * @param id 学员考试结果主键
     * @return 学员考试结果
     */
    @Override
    public ScStudentTestexamResult selectScStudentTestexamResultById(Long id)
    {
        return scStudentTestexamResultMapper.selectScStudentTestexamResultById(id);
    }

    /**
     * 查询学员考试结果列表
     * 
     * @param scStudentTestexamResult 学员考试结果
     * @return 学员考试结果
     */
    @Override
    public List<ScStudentTestexamResult> selectScStudentTestexamResultList(ScStudentTestexamResult scStudentTestexamResult)
    {
        List<ScStudentTestexamResult> scStudentTestexamResults = scStudentTestexamResultMapper.selectScStudentTestexamResultList(scStudentTestexamResult);

        //绑定考试题目 通过考试题目绑定题目
        scStudentTestexamResults.forEach(item -> {
            item.setScTestexamQuestion(scTestexamQuestionMapper.selectScTestexamQuestionById(item.getTestexamquestionid()));
            if(item.getScTestexamQuestion() != null)
                item.setScQuestion(scQuestionService.selectScQuestionById(item.getScTestexamQuestion().getQuestionid()));
        });
        return scStudentTestexamResults;
    }

    /**
     * 新增学员考试结果
     * 
     * @param scStudentTestexamResult 学员考试结果
     * @return 结果
     */
    @Override
    public int insertScStudentTestexamResult(ScStudentTestexamResult scStudentTestexamResult)
    {
        return scStudentTestexamResultMapper.insertScStudentTestexamResult(scStudentTestexamResult);
    }

    /**
     * 修改学员考试结果
     * 
     * @param scStudentTestexamResult 学员考试结果
     * @return 结果
     */
    @Override
    public int updateScStudentTestexamResult(ScStudentTestexamResult scStudentTestexamResult)
    {
        return scStudentTestexamResultMapper.updateScStudentTestexamResult(scStudentTestexamResult);
    }

    /**
     * 批量删除学员考试结果
     * 
     * @param ids 需要删除的学员考试结果主键
     * @return 结果
     */
    @Override
    public int deleteScStudentTestexamResultByIds(Long[] ids)
    {
        return scStudentTestexamResultMapper.deleteScStudentTestexamResultByIds(ids);
    }

    /**
     * 删除学员考试结果信息
     * 
     * @param id 学员考试结果主键
     * @return 结果
     */
    @Override
    public int deleteScStudentTestexamResultById(Long id)
    {
        return scStudentTestexamResultMapper.deleteScStudentTestexamResultById(id);
    }


}
